/*
 * StartApp.java
 *
 * Created on May 6, 2005, 11:30 AM
 */

package com.bff.mpd.musicjukebox.lib;

import com.bff.bjj.utils.Resources;
import com.bff.mpd.musicjukebox.ui.ErrorDialog;
import com.bff.mpd.musicjukebox.ui.MainFramePlayerTop;
import com.bff.mpd.musicjukebox.ui.SplashPropertiesFrame;
import com.bff.mpd.musicjukebox.ui.SplashScreen;

import javax.swing.*;


/**
 * @author Bill
 */
public class StartMPD {
    private static JukeboxProperties jp = null;

    /**
     * Creates a new instance of StartApp
     */
    public StartMPD() {
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIManager.put("Slider.paintValue", Boolean.FALSE);
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        runApp();
    }

    public static void runApp() {
        jp = JukeboxProperties.getInstance();
        if (JukeboxProperties.getStartupException() != null) {
            new ErrorDialog(new JFrame(),
                    Resources.getMessage(Resources.LABEL_KEY.ERROR_STARTUP),
                    JukeboxProperties.getStartupException());
        } else {
            if (checkSettings()) {
                SplashScreen sp = new SplashScreen(false);
                sp.setIndeterminate(true);
                new MainFramePlayerTop(sp).setVisible(true);
            } else {
                SplashPropertiesFrame spf = new SplashPropertiesFrame();
                spf.setVisible(true);
            }
        }
    }

    private static boolean checkSettings() {
        if (jp.exists()) {
            return (true);
        }
        return (false);
    }
}
